/*-----------------------------------------------------------------------------
Archivo:      test_counter.c
Autor:	      Amilcar Erazo
	            Debe compilarse con la herramienta genpat.
------------------------------------------------------------------------------*/

#include <stdio.h>
#include "genpat.h"

char* inttostr(int entier) {
  char* str;
  str = (char *) mbkalloc (32 * sizeof(char));
  sprintf(str,"%d",entier);
  return(str);
}

main() {
  DEF_GENPAT("test_pc");

  DECLAR("clk_i"        ,":2","B", IN   ,	      ""      , "");
  DECLAR("rst_i"          ,":2","B",IN    ,         ""       ,"");
  DECLAR("load_i"          ,":2","B",IN    ,         ""       ,"");
  DECLAR("load_data_i"   ,":2","B", IN ,	"5 downto 0"  , "");
  DECLAR("counter_o"   ,":2","B", OUT  ,	"5 downto 0"  , "");

  LABEL("pc");
  
  SETTUNIT("ns");

  AFFECT("0"    , "clk_i" , "1");
  AFFECT("0"    , "rst_i",   "1");
  AFFECT("0"    , "load_i",   "0");
  AFFECT("0"    , "load_data_i",   "0b000000");
  AFFECT("+150"    , "rst_i",   "0");
  AFFECT("0"    , "clk_i",   "1");

  int i = 0;
  for(i; i<20; i++) {  
    AFFECT("+50","clk_i",inttostr(i%2));
	if ( i == 8 ){
		  AFFECT("+0"    , "load_i",   "1");
 		  AFFECT("+0"    , "load_data_i",   "0b101010");
	}
	if ( i == 10 ){
		 AFFECT("+0"    , "load_i",   "0");
	}
	if ( i == 15 ){
		AFFECT("+0"    , "rst_i",   "1");
	}
	if ( i == 16 ){
		AFFECT("+0"    , "rst_i",   "0");
	}
  }

  SAV_GENPAT();

  exit(0);
}
